<?
if(!$_SESSION['memberID']){
    header('Location:/new/d/shops/gtindex.html');
    exit;
}
include_once("/var/www/html/new/com.inc.php");
include_once('/var/www/html/new/d/common/autoload.php');
include_once("/var/www/html/new/d/common/page.php");
include_once("/var/www/html/new/d/shops/call/OrderRecord.php");
include_once("/var/www/html/new/d/class/ProOrder.php");
// include_once("/var/www/html/new/conf/yd.le.je");
// include_once("/var/www/html/new/d/common/yd.le.je");//连接云顶的数据库
if($_SESSION['domain_mid']==7517){
    $_SESSION['sdtype'] = 5;
    $_SESSION['dtype'] = 5;
}
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($_SESSION['memberID']);

// $ydle=new yd_go_sql();
// $ydle->connect(); 
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID = $_SESSION['sid'];
$_REQUEST['begintime']='2014-12-07';
$_REQUEST['endtime']= date('Y-m-d');
$_REQUEST['distributor'] = $_SESSION['domain_mid'];
if($_SESSION['domain_mid']!=7517){
    $_REQUEST['distributor'] = $_SESSION['sid'];
}

$currentPage = $_REQUEST["currentPage"] ? $_REQUEST["currentPage"]:1;
$pageSize = $_REQUEST['pageSize'] ? $_REQUEST["pageSize"]:30;
$pOrder=buyProOrderObject($memberID,$s,$_SESSION['sdtype']);
$r=$pOrder->_orderlist($currentPage,$pageSize);


$arr = $childOrder = array();
foreach($r as $key => $row){
	// 处理
	$concat = (string)$row['mainOrder']->UUconcat_id;
	$orderid = (string)$row['mainOrder']->UUordernum;
	if($concat==0 || $orderid==$concat){
		$arr[$orderid] = $row;// 主订单
        continue;
	}
	if($concat!=$orderid){ // 子订单
        $childOrder[] = $row; 
    }
}
$r = $arr;

foreach($childOrder as $k=>$row){
    $concat = (string)$row['mainOrder']->UUconcat_id;
    $orderid = (string)$row['mainOrder']->UUordernum;
    if($r[$concat]){
        $r[$concat]['childOrder'][]=$row;
    }
}
// print_r($r);
// 判断订单是否为主订单  true 为主订单
function isMainOrder($field){
	return ($field=='main' || $field!=0 ) ? true:false;
}
// 复票订单主订单
function echoMainOrder($obj){
	return ((String)$obj->UUconcat_id=='main') ? (String)$obj->UUordernum:(String)$obj->UUconcat_id;
}
$count=$pOrder->orderlistTotal();
$uuStatus = array(
    0=>"未使用",
    1=>"<em class='green'>已使用</em>",
    2=>"已过期",
    3=>"<em class='red'>已取消</em>",
    4=>"被替代",
    5=>"<em class='green'>已使用</em><br/><em class='red'>(被修改)</em>",
    6=>"已撤销",
    7=>"部分使用"
);
?>
<? include("ggheader.php") ?>
<style>
.mem_time {width: 100%;background-color: white;height: 40px;line-height:40px;}
</style>
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/page.css"/>
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/shops/css/gmem.css"/>
<script language="javascript" src="http://www.12301.cc/js/WdatePicker.js"></script>
<div class="mem_con">
    <div class="mem_left">
        <div id="mem_photo"><a href="javascript:showBg();"  class="info_img"><img src="<?=$m_info['headphoto']?$m_info['headphoto']:"http://www.12301.cc/images/touxiang.png"?>" onerror="javascript:this.src='http://www.12301.cc/images/touxiang.png'" title="点击修改头像"/></a></div>
        <ul>
            <li><a href="gmem.html">订单中心</a></li>
            <li><a href="gmem_Data.html">个人资料</a></li>
            <li><a href="gmem_pass.html">修改密码</a></li>
            <!-- <li><a href="#">安全退出</a></li> -->
        </ul>
    </div>
    <div class="mem_right">
		<div class="mem_time">
			<form action="" method="get"  name="form" >
			<span class="lt">下单时间：</span>
			<input type="text" data-t="bt" id="txtStartTime" value="<?=$_GET['begintime']?>" name="begintime" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/> 至
			<input type="text" data-t="et" id="txtEndTime"  value="<?=$_GET['endtime']?>" name="endtime" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/>
			<input type="submit" value="查询">
		</div>
        <div id="" class="hcon">
            <table class="proTable fixed " ><!-- id="tbl_evlt" -->
                <thead id="proTableHead">
                    <tr>
                        <th class="col_1">订单号</th>
                        <th class="col_2">产品信息</th>
                        <th class="col_3">取票人信息</th>
                        <th class="col_4">订单状态</th>
                        <th class="col_5">总金额</th>
                        <th class="col_6">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 第1个产品 -->
                    <?
                    foreach($r as $row):
                    
                        // print_r($row);
                        $childNum = count($row['childOrder']);//统计子票订单数
                        $orderid=(string)$row['mainOrder']->UUordernum;
                        // $sql = "select id from uu_discuss where orderid='$orderid' limit 1";
                        // $GLOBALS['le']->query($sql);
                        //$GLOBALS['le']->fetch_assoc();
                        // $commentId = $le->f('id');
                    ?>
                    <tr class="listHead">
                        <td colspan="8">
                            <div>
                            <a href="/new/d/shops/gdetail.html?lid=<?=(int)$row['mainOrder']->UUlid?>" title="<?=(string)$row['mainOrder']->UUltitle?>" class="title" target="_blank"><?=(string)$row['mainOrder']->UUltitle?></a>
                            <p class="rt">
                                <span class="span">下单时间：<?=(string)$row['mainOrder']->UUordertime?></span>
                                <span class="span">有效期：<?=(string)$row['mainOrder']->UUbegintime?> 至 <?=(string)$row['mainOrder']->UUendtime?></span>
                                <span class="span span3">验证时间：<?=(string)$row['mainOrder']->UUdtime!="0000-00-00 00:00:00"?(string)$row['mainOrder']->UUdtime:"未验证"?></span>
                            </p>
                            </div>
                        </td>
                    </tr>
                    <tr class="listBody <?if(!$childNum)echo 'borderBottom';?>" >
                        <td class="col_1 col codeNum" rowspan="<?=$childNum + 1?>">
                        <a href="" class="ordernb"><?=(string)$row['mainOrder']->UUordernum?></a>
                        <?if($row['mainOrder']->UUstatus==0 && $row['mainOrder']->UUpaystatus==1):?>
                            <?if(isMainOrder($row['mainOrder']->UUconcat_id)):?>
                            <span  id="getCode"></span>
                            <input type="button" class="getCode" value="获取凭证号" data="<?=(string)$row['mainOrder']->UUordernum?>"/>
                            <?else:?>
                            <span  id="getCode"></span>
                            <input type="button" class="getCode" value="获取凭证号" data="<?=(string)$row['mainOrder']->UUordernum?>"/>
                            <?endif;?>
                        <?endif;// 判断获取凭证号按钮出现结束?>    
                        <?if((string)$row['mainOrder']->UUremotenum){?>
                        <span class="f_orderNum"><?=(string)$row['mainOrder']->UUremotenum?></span>
                        <?}?>
                        </td>
                        <td class="col_2 col">
                        【<?=(string)$row['mainOrder']->UUttitle?>】<span class="numPrice"> * <i><?=(string)$row['mainOrder']->UUtnum?></i> 张 * &yen;<i><?=(string)$row['mainOrder']->UUtprice/100?></i></span>
                        </td>
                        <td class="col_3 col" rowspan="<?=$childNum + 1?>">
                            <p class="name2"><?=(string)$row['mainOrder']->UUordername?></p>
                            <p class="tell"><?=(string)$row['mainOrder']->UUordertel?></p>
                        </td>
                        <td class="col_6 col" rowspan="<?=$childNum + 1?>">
                        <span rowspan="<?=$row['totalOrder']?>">
                            <p>
                                <?=$uuStatus[(string)$row['mainOrder']->UUstatus]?>
                                <?if((string)$row['mainOrder']->UUstatus==2 && (string)$row['mainOrder']->UUpaystatus==2) echo '<br/><span style="color:red;">(未支付)</span>';?>
                            </p>
                            <p class="green">
                            <?if($row['mainOrder']->UUstatus==0){?>
                            <?=OrderRecord::$paystatusT[(string)$row['mainOrder']->UUpaystatus]?>
                            <?}?>
                            </p>
                        </td>
                        <td class="col_7 col" rowspan="<?=$childNum + 1?>">

                        <?if(!isMainOrder($row['mainOrder']->UUconcat_id)):?>
                        合计<span class="totalPrice">&yen;<i><?=((int)$row['mainOrder']->UUtprice*(int)$row['mainOrder']->UUtnum)/100?></i></span>
                        <?else:?>
                        <?
                            $total = 0;
                            foreach($row['childOrder'] as $cr){
                                // $total = $total + (string)$cr['totalPrice']/100 ;
                                $total = $total + ((int)$cr['mainOrder']->UUtprice*(int)$cr['mainOrder']->UUtnum)/100;
                            }
                            $total += ((int)$row['mainOrder']->UUtprice*(int)$row['mainOrder']->UUtnum)/100;
                        ?>
                        合计<span class="totalPrice">&yen;<i><?=$total?></i></span>
                        <?endif;?>
                        </td>
                        <td class="col_8 col" rowspan="<?=$childNum + 1?>">
                        <?
                            // print_r($row);
                            $ordernum = (string)$row['mainOrder']->UUordernum;// 订单号
                            if((string)$row['orderAlipay']){ // 支付
								if($_SESSION['domain_mid']==7517){
									echo '<a href="/new/d/shops/alipayOrder_c.html?ordernum='.$ordernum.'" target="_blank">支付</a>';
								}else{
									echo '<a href="/new/d/shops/alipayOrder_c_dev.html?ordernum='.$ordernum.'" target="_blank">支付</a>';
								}
                                
                            }elseif($row['mainOrder']->UUstatus==0 && $row['mainOrder']->UUpaystatus==1){   // 退票
								echo '<a  class="order_cancel" href="call/handle.php?from=order_cancel&ordernum='.$ordernum.'" data="'.$ordernum.'">退票</a>';
                                
                                echo '<br/><a act="cancel" class="resend" href="call/handle.php?from=order_resend&&ordernum='.$ordernum.'">重发</a><br/>';
                            }
                            
                        ?>
                        </td>
                    </tr>
                    <?foreach($row['childOrder'] as $cr):?>
                    <tr class="listBody borderBottom borderTop">
                        <td class="col_2 col">
                            【<?=(string)$cr['mainOrder']->UUttitle?>】
                            <span class="numPrice"> * <i><?=(string)$cr['mainOrder']->UUtnum?></i> 张 * &yen;<i><?=(string)$cr['mainOrder']->UUtprice/100?></i></span>
                        </td>
                    </tr>
                    <?endforeach;//子票?>
                        <tr class="marTop"><td colspan="8"></td></tr>
                    <?endforeach;?>
                </tbody>
            </table>
            <?page($count,$currentPage,$pageSize,$order,$by);?>
        </div>
    </div>	
</div>	
<script src="http://www.12301.cc/js/ui/PopWindow.js" type="text/javascript"></script>
<script>
/*获取凭证号*/
$(function(){
	$(".getCode").click(function(){
        var orderId= $(this).attr("data");
		$.ajax({
            "url":"call/handle.php?from=orderView&act=getCode&ordernum="+orderId,
            "dataType":"json",
            "success":function(json){
				alert(json.msg);
            }
        })
	})
});

$(".resend").click(function(){
	if($(this).attr("act")=="cancel"){
		if(!confirm("确定要重发短信？")) return false;
	}
	$.ajax({
		"url":$(this).attr("href"),
		"dataType":"json",
		"success":function(data){
			if(data.outcome==1){
				alert("重发成功");
			}else{
				alert("重发失败:"+data.msg);
			}
		}
	})
	return false;
});
$(".order_cancel").click(function(){
	var href = $(this).attr("href"),ordernum=$(this).attr("data");
	$.ajax({
		"url":"call/handle.php?from=cancelCheck&ordernum="+ordernum,
		"dataType":"json",
		"success":function(data){
			if(data.outcome==1){

				if(data.code!=100){
					alert("取消需支付 "+data.cost+" 元的退款手续费费用，您的账户余额不足，无法取消，请先充值。");
					return false;
				}
				var msg="您确定要取消吗？";
				if(data.cost>0){
					msg = "取消需扣除 "+data.cost+" 元的退款手续费费用，您确定要取消吗？";
				}
				if(!confirm(msg)) return false;
				$.ajax({
					"url":href,
					"dataType":"json",
					"success":function(data){
						if(data.outcome==1){
							alert("取消成功");
							window.location=window.location.href;
						}else{
							alert("取消失败"+data.msg);
						}
						
					}
				});
				return false;
			}else{
				alert("请求出错，请重试");
			}
		}
	});
	return false;
});

var popWindow=new PopWindow();
	$(".alter").click(function(){
        
		$.ajax({
			"url":$(this).attr("href"),
			"success":function(data){
				popWindow.open(data);
				$("form.changetnum input.cancel").click(function(){
					popWindow.close();
					
				});
				$("form.changetnum").submit(function(){
					popWindow.close();
					var str=$(this).serialize();
					$.ajax({
						"url":"/new/d/module/alipay_refund/alipay.refund.php",
						"dataType":"json",
						"type": 'POST',
						"data": str,
						"success":function(data){
							if(data.status=='ok'){
								alert(data.msg);
								window.location=window.location.href;
							}
							else if (data.status=='fail') {
								alert(data.msg);
							}
						} 
					}); 
					return false;
				});
				
			}
		})
		return false;
	});
/*修改头像*/
function uploadevent(status,picUrl,callbackdata){
    closeBg();
    status += ''; 
    switch(status){
     case '1':
		var time = new Date().getTime();
		// var filename162 = picUrl+'_162.jpg';
        // alert(filename162);
        document.getElementById('user_photo').src=""+picUrl+"";
		 window.parent.location='/new/d/shops/gmem.html';
        break;
    case '-1':
        window.parent.location='/new/d/shops/gmem.html';
        break;
    default:
		window.parent.location='/new/d/shops/gmem.html';
    } 
}

/*修改头像遮罩*/
function showBg() { 
	var bh = $("html").height(); 
	var bw = $("html").width(); 
	$("#fullbg").css({ 
	height:bh, 
	width:bw, 
	display:"block" 
	}); 
	$("#dialog").show(); 
} 
function closeBg() { 
    $("#fullbg,#dialog").hide(); 
} 


$("#txtStartTime").bind("click focus", function () {  
	
		   var endtimeTf = $dp.$('txtEndTime');             
		   WdatePicker({                            
			   maxDate: '#F{$dp.$D(\'txtEndTime\')}',      
			   dateFmt: "yyyy-MM-dd",              
			   onpicked: function () { endtimeTf.focus(); }          
				});         
		   });          
		   $("#txtEndTime").bind("click focus", function () {       
				WdatePicker({           
				   minDate: '#F{$dp.$D(\'txtStartTime\')}', 
				   dateFmt: "yyyy-MM-dd"       
			   });         
		   });
</script>
<?php include("ggfoot_m.php");?>
</body>
</html>
<div id="fullbg"></div> 
<div id="dialog"> 
<p class="close"><a href="#" onclick="closeBg();">X</a>  
<div >
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
	WIDTH="650" HEIGHT="450" id="myMovieName">
	<PARAM NAME=movie VALUE="avatar.swf">
	<PARAM NAME=quality VALUE=high>
	<PARAM NAME=bgcolor VALUE=#FFFFFF>
	<param name="flashvars" value="imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false" />
	<EMBED src="avatar.swf" quality=high bgcolor=#FFFFFF WIDTH="650" HEIGHT="450" wmode="transparent" flashVars="imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false"
	NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" allowScriptAccess="always"
	PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
	</EMBED>
</OBJECT>  

